<!-- 添加放箱公司 -->
<template>
  <div class="new-boxcom-dialog">
    <el-dialog
      width="900px"
      class=""
      top="6vh"
      title="添加放箱公司"
      :visible="$store.state.dialog.newBoxcom"
      @close="close">
      <el-row>
        <el-col :span="24">
          <el-card shadow="hover">
            <el-form :model="order" :rules="rules" ref="order" label-width="100px" size="mini">
              <el-row>
                <el-col :span="8">
                  <el-form-item label="注册账号" prop="accountNumber">
                    <el-input v-model="order.accountNumber"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item>
                    <el-button type="primary" @click="seachdiver()">查询</el-button>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
            <el-table
              :data="tableData2"
              style="width: 100%"
              @selection-change="handleSelectionChange"
              height="100">
              <el-table-column type="selection" align="center" width="50"></el-table-column>
              <el-table-column
                prop="CompanyName"
                label="公司名称"
                width="110">
              </el-table-column>
              <el-table-column
                prop="CompanySite"
                label="公司类型">
              </el-table-column>
              <el-table-column
                prop="FullName"
                label="公司联系人">
              </el-table-column>
              <el-table-column
                prop="Mobile1"
                label="公司联系电话"
                width="130">
              </el-table-column>
              <el-table-column
                prop="Address"
                label="公司地址"
                width="130">
              </el-table-column>
              <el-table-column
                prop="NickName"
                label="注册账号"
                width="120">
              </el-table-column>
            </el-table>
          </el-card>
        </el-col>
      </el-row>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="addPutBoxCompany" size="mini">添 加</el-button>
        <el-button type="info" @click="close" size="mini">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {addPutBoxCompany, GetUserInfo} from '../api/customerManagement'
export default {
  data () {
    return {
      order: {
        accountNumber: ''
      },
      tableData2: [],
      multipleSelection: [],
      rules: {
        accountNumber: [
          { required: true, message: '请输入注册账号', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    close () {
      this.$store.commit('hide_new_boxcom_dialog')
    },
    // 查询
    async seachdiver () {
      if (this.order.accountNumber === '') {
        this.$message({
          type: 'warning',
          message: '请输入注册账号'
        })
        return false
      }
      const res = await GetUserInfo(this.order)
      if (res.status === 200) {
        this.tableData2 = res.data
      } else {
        this.$notify({
          title: '错误',
          message: res.msg,
          type: 'error'
        })
      }
    },
    handleSelectionChange (val) {
      this.multipleSelection = val
    },
    // 新增放箱公司
    async addPutBoxCompany () {
      if (this.multipleSelection.length !== 1) {
        this.$message({
          message: '请只选择一条消息',
          type: 'warning'
        })
        return false
      }
      const res = await addPutBoxCompany({
        putBoxCompanyId: this.multipleSelection[0].UserId // 客户编号
      })
      if (res.status === 200) {
        this.$notify({
          title: '提示',
          message: res.msg,
          type: 'success'
        })
        this.$parent.getPutBoxList(1, 15)
        this.$store.commit('hide_new_boxcom_dialog')
      } else {
        this.$notify({
          title: '错误',
          message: res.msg,
          type: 'error'
        })
      }
    }
  }
}
</script>

<style scoped lang="less">

</style>
